package com.kexilo.system.audit.service;

import com.kexilo.core.audit.domain.AuditOperLog;
// TODO: 将在阶段二重构为插件中的DTO
// import com.kexilo.core.shared.dto.OperationLogDTO;
import com.kexilo.system.audit.mapper.AuditOperLogMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 审计日志服务
 * 
 * @author Kexilo
 */
@Service
public class AuditLogService {
    
    private static final Logger log = LoggerFactory.getLogger(AuditLogService.class);
    
    @Autowired
    private AuditOperLogMapper auditOperLogMapper;
    
    // TODO: 将在阶段二重构为插件调用方式
    /*
    @Transactional
    public void saveOperationLog(OperationLogDTO operationLogDTO) {
        try {
            // 将DTO转换为audit模块的实体
            AuditOperLog auditOperLog = convertToEntity(operationLogDTO);
            
            // 保存到数据库
            auditOperLogMapper.insertOperLog(auditOperLog);
            
            log.debug("保存操作日志成功: {}", operationLogDTO.getTitle());
            
        } catch (Exception e) {
            log.error("保存操作日志失败: {}", operationLogDTO.getTitle(), e);
            throw new RuntimeException("保存审计日志失败", e);
        }
    }
    */
    
    // TODO: 将在阶段二重构为插件调用方式
    /*
    private AuditOperLog convertToEntity(OperationLogDTO dto) {
        AuditOperLog entity = new AuditOperLog();
        
        entity.setTitle(dto.getTitle());
        entity.setBusinessType(dto.getBusinessType() != null ? dto.getBusinessType().ordinal() : null);
        entity.setMethod(dto.getMethod());
        entity.setRequestMethod(dto.getRequestMethod());
        entity.setOperName(dto.getOperName());
        entity.setDeptName(dto.getDeptName());
        entity.setOperUrl(dto.getOperUrl());
        entity.setOperIp(dto.getOperIp());
        entity.setOperLocation(dto.getOperLocation());
        entity.setOperParam(dto.getOperParam());
        entity.setJsonResult(dto.getJsonResult());
        entity.setStatus(dto.getStatus());
        entity.setErrorMsg(dto.getErrorMsg());
        entity.setOperTime(dto.getOperTime());
        entity.setCostTime(dto.getCostTime());
        entity.setTraceId(dto.getTraceId());
        entity.setSpanId(dto.getSpanId());
        entity.setTenantId(dto.getTenantId());
        entity.setUserAgent(dto.getUserAgent());
        entity.setBrowser(dto.getBrowser());
        entity.setOs(dto.getOs());
        
        return entity;
    }
    */
}
